//
//  ReSetRealNameAuthViewController.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/5.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "ReSetRealNameAuthViewController.h"

@interface ReSetRealNameAuthViewController ()

@property (nonatomic,strong) UIView *bgView1;
@property (nonatomic,strong)UITextField * textField1;
@property (nonatomic,strong)UITextField * textField2;


@end

@implementation ReSetRealNameAuthViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    
    [self setProperty];
    
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden=YES;
    
    //    if ([_Status isEqualToString:@"UI_1"]) {
    [self createUI_1];
    //    }else{
    //        [self loadData];
    //    }
    
    
}

-(void)setProperty{
    
    self.view.backgroundColor=RGB(255, 255, 255);
    
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden=YES;
    
    self.baseVcTitle = @"修改实名认证";
    
}
-(void)createUI_1{
    
    [_bgView1 removeFromSuperview];
    
    _bgView1 = [[UIView alloc]init];
    [self.bgView addSubview:_bgView1];
    [_bgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(kStatusBarAndNavigationBarHeight);
        make.left.right.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = @"为了您的资金安全，需要验证您的身份证才可以进行其他操作，认证信息一经验证不能修改，请务必如实填写。";
    label.font = [UIFont systemFontOfSize:12];
    label.numberOfLines = 0;
    label.textColor = RGB(158, 169, 181);
    label.textAlignment=NSTextAlignmentLeft;
    [_bgView1 addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView1.mas_top).offset(30);
        make.left.equalTo(self.bgView1.mas_left).offset(15);
        make.width.equalTo(@(G_SCREENWIDTH-30));
    }];
    
    [self setTitle:@"真实姓名" andIndex:1 andPlaceholder:@"请输入您的真实姓名" andKeyboardType:UIKeyboardTypeNamePhonePad andSecureTextEntry:YES];
    [self setTitle:@"身份证号码" andIndex:2 andPlaceholder:@"请输入您的身份证号码" andKeyboardType:UIKeyboardTypeDefault andSecureTextEntry:YES];
    
    
    [self.rightBtn setTitle:@"确认" forState:UIControlStateNormal];
    [self.rightBtn setTitleColor:RGB(99, 139, 219) forState:UIControlStateNormal];
    
}


-(void)setTitle:(NSString *)title andIndex:(NSInteger)index andPlaceholder:(NSString *)Placeholder andKeyboardType:(UIKeyboardType)type andSecureTextEntry:(BOOL)isSecureTextEntry{
    
    CGFloat H =95,T=(index-1)*95+100;
    
    UIView * bgview = [[UIView alloc]init];
    bgview.frame = CGRectMake(0, T, G_SCREENWIDTH, H);
    [self.bgView1 addSubview:bgview];
    
    UILabel *label = [[UILabel alloc] init];
    label.text = title;
    label.font = [UIFont systemFontOfSize:12];
    label.textColor = RGB(30, 63, 89);
    label.textAlignment=NSTextAlignmentLeft;
    [bgview addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgview.mas_top).offset(20);
        make.left.equalTo(bgview.mas_left).offset(15);
        make.width.equalTo(@(120));
        make.height.equalTo(@(30));
    }];
    
    UITextField * textField=[[UITextField alloc]init];
    //    textField.secureTextEntry = isSecureTextEntry;
    textField.tag=500+index;
    [bgview addSubview:textField];
    [self setTextField:textField WithPlaceholder:Placeholder  and:type];
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bgview.mas_bottom);
        make.left.equalTo(bgview.mas_left).offset(15);
        make.right.equalTo(bgview.mas_right).offset(-15);
        make.height.equalTo(@(50));
    }];
    if (index==1) {
        _textField1=textField;
    }else if (index==2){
        _textField2=textField;
    }
    
    
    UIView * line = [[UIView alloc]init];
    [bgview addSubview:line];
    line.backgroundColor = RGB(231, 235, 238);
    [bgview addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bgview.mas_bottom).offset(-1);
        make.left.equalTo(bgview.mas_left).offset(15);
        make.right.equalTo(bgview.mas_right).offset(-15);
        make.height.equalTo(@(1));
    }];
    
    
}


-(void)setTextField:(UITextField*)textField WithPlaceholder:(NSString *)placeholder and:(UIKeyboardType)type  {
    
    
    textField.placeholder=placeholder;
    textField.borderStyle = UITextBorderStyleNone;
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    
    //、    userNameTF.delegate = self;
    textField.autocorrectionType = UITextAutocorrectionTypeNo;
    textField.backgroundColor=[UIColor clearColor];
    textField.font = [UIFont systemFontOfSize:15];
    textField.textColor = RGB(40, 40, 40);
    textField.textAlignment = NSTextAlignmentLeft;
    //    textField.returnKeyType = UIReturnKeyDefault;
    //    textField.keyboardType = type;
    [textField setValue:RGB(190, 190, 190) forKeyPath:@"_placeholderLabel.textColor"];
    [textField setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
    [textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:(UIControlEventEditingChanged)];
    
}

-(void)textFieldDidChange:(UITextField *)textField{
    textField.text= [textField.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    if (textField.tag==501) {
        
    }else if(textField.tag==502){
        
    }
}


#pragma mark-确认
-(void)rightAction{
    
    if (_textField1.text.length<1) {
        [HUD showErrorMessage:@"请输入真实姓名！"];
        return;
    }
    
    if (_textField2.text.length<1) {
        [HUD showErrorMessage:@"请输入身份证号码！"];
        return;
    }
    
    
    NSString * URL = [NSString stringWithFormat:@"%@kyc/updateLv1",DEFAULTSEVERBASEURL];
    __weak __typeof(self)wself = self;
    
 
    
    [MOLoadHttpsData PostHttpDataWithUrlStr:URL Dic:@{@"true_name":_textField1.text,@"certificate_type":@"1",@"identification_number":_textField2.text,@"access_token":[LoginModel GetValue:DL_token]} SuccessBlock:^(id  _Nonnull responseObject) {
        NSDictionary * dic = responseObject;
        NSString * code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        if ([code isEqualToString:@"0"]) {
            
            [HUD showSuccessMessage:dic[@"msg"]];
            [wself.navigationController popViewControllerAnimated:YES];
            
        }else{
            [HUD showErrorMessage:dic[@"msg"]];
        }
        
    } FailureBlock:^(id  _Nonnull error) {
        
    }];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
